<?php



if( ! ini_get('date.timezone') )
{
   date_default_timezone_set('GMT');
}

$svn = !empty($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null;

define("SERVERNAME", "localhost");
define("USER", "root");
define("PWD", "");
define("DBNAME", "tracking_money");






$g_link = false;

function getUrlBase() {
  $url  = @( $_SERVER["HTTPS"] != 'on' ) ? 'http://'.$_SERVER["SERVER_NAME"] :  'https://'.$_SERVER["SERVER_NAME"];
  $url .= ( $_SERVER["SERVER_PORT"] !== 80 ) ? ":".$_SERVER["SERVER_PORT"] : "";
  $url .= $_SERVER["REQUEST_URI"];
  return $url;
}



function connection($pdo=false){
	global $g_link;
	// if( $g_link ) return $g_link;	

	if(!$pdo){
		if($g_link) @mysql_close($g_link);
		
		$g_link = mysql_connect( SERVERNAME, USER, PWD) or die('Could not connect to server.' );
		try {
			@mysql_set_charset('utf8',$g_link);
			mysql_select_db(DBNAME, $g_link);
		} catch (PDOException $e) {
			die("Failed to get DB handle: " . $e->getMessage());
		}
		
	}else{
		try {
			$g_link = new PDO("mysql:host=".SERVERNAME.";dbname=".DBNAME.";charset=utf8", USER, PWD);
			$g_link->exec("set names utf8");
		} catch (PDOException $e) {
			die("Failed to get DB handle: " . $e->getMessage());
		}
		
	}
	
	return $g_link;
}

function writelog($file,$content){
	
	@file_put_contents($file, $content."\n", FILE_APPEND | LOCK_EX);
}


function cleanUpDB()
{
	global $g_link;
	if( $g_link != false )
		mysql_close($g_link);
	$g_link = false;
}



require("common.php");
?>